﻿using System;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace SfsTools.Core
{
    /// <summary>
    /// The exception thrown when a duplicate <see cref="BaseFileEntry"/> is found in the index area.
    /// </summary>
    [Serializable]
    public class DuplicateFileException : InvalidIndexAreaException
    {
        #region Constructors

        /// <overloads>Initializes a new instance of <see cref="DuplicateFileException"/>.</overloads>
        /// <summary>
        /// Initializes a new instance of <see cref="DuplicateFileException"/> with its message string set to the empty string (""), and its inner exception set to <see langword="null"/>.
        /// </summary>
        /// <remarks>
        /// <para>The constructor initializes the <see cref="Exception.Message"/> property of the new instance to a system-supplied message that describes the error, such as <em>"An I/O error occurred while performing the requested operation."</em>. This message takes into account the current system culture.</para>
        /// </remarks>
        [DebuggerStepThrough]
        public DuplicateFileException()
            : base(Translation.Resources.GetString(typeof(DuplicateFileException).Name))
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="DuplicateFileException"/> with a specified error message.
        /// </summary>
        /// <param name="path">The full path to the directory that has duplicates.</param>
        /// <remarks>
        /// <para>The constructor initializes the <see cref="Exception.Message"/> property of the new instance to a system-supplied message that describes the error, such as <em>"An I/O error occurred while performing the requested operation."</em>. This message takes into account the current system culture.</para>
        /// </remarks>
        [DebuggerStepThrough]
        public DuplicateFileException(String path)
            : base(String.Format(Translation.Resources.GetString(String.Concat(typeof(DuplicateDirectoryException).Name, '1')), path))
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="DuplicateFileException"/> with a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not <see langword="null"/>, the current exception is raised in a <see langword="catch"/> block that handles the inner exception.</param>
        /// <remarks><para>An exception that is thrown as a direct result of a previous exception should include
        /// a reference to the previous exception in the <see cref="Exception.InnerException"/> property.
        /// The <see cref="Exception.InnerException"/> property returns the same value that is passed into the constructor,
        /// or <see langword="null"/> if the <see cref="Exception.InnerException"/> property does not supply the inner
        /// exception value to the constructor.</para></remarks>
        [DebuggerStepThrough]
        public DuplicateFileException(Exception innerException)
            : base(Translation.Resources.GetString(typeof(DuplicateFileException).Name), innerException)
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="DuplicateFileException"/> with a specified error message and a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="message">The error message that explains the reason for the exception.</param>
        /// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException"/> parameter is not <see langword="null"/>, the current exception is raised in a <see langword="catch"/> block that handles the inner exception.</param>
        /// <remarks><para>The content of the <paramref name="message"/> parameter is intended
        /// to be understood by humans. The caller of this constructor is required to
        /// ensure that this string has been localized for the current system culture.</para>
        /// <para>An exception that is thrown as a direct result of a previous exception should include
        /// a reference to the previous exception in the <see cref="Exception.InnerException"/> property.
        /// The <see cref="Exception.InnerException"/> property returns the same value that is passed into the constructor,
        /// or <see langword="null"/> if the <see cref="Exception.InnerException"/> property does not supply the inner
        /// exception value to the constructor.</para></remarks>
        [DebuggerStepThrough]
        public DuplicateFileException(String message, Exception innerException)
            : base(message, innerException)
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="DuplicateFileException"/> with the specified serialization and context information.
        /// </summary>
        /// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
        /// <remarks>This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see 
        /// <see href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconserialization.htm">XML and SOAP Serialization</see>.</remarks>
        [DebuggerStepThrough]
        protected DuplicateFileException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion
    }
}
